# import operate

# print(operate.add(25,10))
# print(operate.sub(25,10))
# print(operate.mul(25,10))
# print(operate.div(25,10))

# from operate import add
# from operate import sub
# from operate import mul
# from operate import div
# from operate import *

# print(add(25,10))
# print(sub(25,10))
# print(mul(25,10))
# print(div(25,10))

# N 总共多少人
# M 每次第几个人出列
# def Josephus(N,M):
#     people = [True] * N
#     print(people)
#     # 
#     count = 0
#     # 列表第几个元素
#     index = 0

#     while count<N-1:
#         # 报数
#         if people[index]:
#             count += 1
#         print(count)
#         # 报数报道M
#         if count == M:
#             people[index] = False
#             count = 0
#             print("出列")
#         index = (index+1)%N

#     # 找到最后剩下的那个
#     for i in range(N):
#         if people[i]:
#             return i+1

# print(Josephus(6,5))

# Josephus(6,5)

def Josephus(N,M):
    # 1. 创建一个N个人的列表
    ls = list(range(1,N))

    # 剩余人数
    sum = N
    # 报数 1 2 3 
    count = 0
    # 索引
    index = 0

    while True:
        # 剩余人数小于3:
        if sum<2:
            break;
        # 如果这个位置不为0 # 报数+1
        if ls[index] != 0:
            count += 1
        # 打印一下
        print(index,":",count)
        # 如果报3
        if count==3:
            ls[index] = 0
            count = 0
            sum -= 1
        # 索引+1
        index = (index+1)%41

